const Router = require('koa-router')
const router = new Router()
const koaBody = require('koa-bodyparser');

const login = require('../model/log_in');
const table = require('../model/table');

router.post('/post_test',koaBody(),ctx=>{
    const name = ctx.request.body.name;
    if(name==='chenxiaoguang'){
        ctx.body={
            'code':299,
            'msg':"hello world"
        }
    }else{
        ctx.body={
            'code':400,
            'msg':name
        }
    }
    
})

router.post('/login',koaBody(),async ctx=>{
    const password = ctx.request.body.password;
    const username = ctx.request.body.username;
    const login_message = await login.DEBARK(username,password);
    ctx.body = login_message;
})

router.get('/get_user',async ctx=>{
    const get_users = await table.GETTABLE();
    ctx.body = get_users;
})

router.get('/get_word',async ctx=>{
    const get_users = await table.GETTABLE();
    ctx.body = get_users;
})

router.get('/get_oneself'),async ctx=>{
    const get_oneself = await table.GETONESELF();
    ctx.body = get_oneself;
}


module.exports = router